Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Fix upsert validation to merge $create and $update schemas#604

Merged
ymc9 merged 3 commits intofeat/client-extensionfrom
copilot/sub-pr-603
Jan 18, 2026
Merged

Fix upsert validation to merge $create and $update schemas#604
ymc9 merged 3 commits intofeat/client-extensionfrom
copilot/sub-pr-603

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 18, 2026

Runtime validation for upsert was only applying the $create schema when plugins defined both $create and $update extended query args, creating a mismatch with TypeScript types which intersect both schemas.

Changes

  • Special-case upsert in validation logic: Check for upsert operation before grouped operation fallthrough and merge both schemas using Zod's merge() when both $create and $update are defined
  • Maintain precedence order: specific operation > merged create/update for upsert > grouped operations > $all
  • Add test coverage: Verify upsert accepts fields from both schemas when they define different properties

Example

const plugin = definePlugin({
  id: 'test',
  queryArgs: {
    $create: z.object({ tracking: z.object({ source: z.string() }).optional() }),
    $update: z.object({ audit: z.object({ reason: z.string() }).optional() })
  }
});

// Now correctly accepts both tracking and audit fields
await db.user.upsert({
  where: { id: 1 },
  create: { name: 'Alice' },
  update: { name: 'Alice Updated' },
  tracking: { source: 'import' },  // from $create
  audit: { reason: 'sync' }         // from $update
});

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 18, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 2 commits January 18, 2026 03:51
- Handle upsert operation specially to match TypeScript type behavior
- When both $create and $update schemas exist, merge them for upsert
- Add test case to verify the fix works correctly

Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 18, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint.prisma.io
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/zenstack-v3/zenstack-v3/node_modules/.pnpm/prisma@6.19.0_magicast@0.3.5_typescript@5.9.3/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.19.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-01-18T03:44:01Z&#34;,&#34;project_hash&#34;:&#34;8029397a&#34;,&#34;cli_path&#34;:&#34;/tmp/tmp-4679-Yq11kJSwcY0M/node_modules/prisma/build/index.js&#34;,&#34;cli_path_hash&#34;:&#34;d07f7360&#34;,&#34;en bash odul�� tsup-node (dns block)
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/zenstack-v3/zenstack-v3/node_modules/.pnpm/prisma@6.19.0_magicast@0.3.5_typescript@5.9.3/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.19.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-01-18T03:44:06Z&#34;,&#34;project_hash&#34;:&#34;5cef3d7a&#34;,&#34;cli_path&#34;:&#34;/tmp/tmp-4679-UNNFlDnJtQVZ/node_modules/prisma/build/index.js&#34;,&#34;cli_path_hash&#34;:&#34;a27cb884&#34;,&#34;en sh sc s (dns block)
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/zenstack-v3/zenstack-v3/node_modules/.pnpm/prisma@6.19.0_magicast@0.3.5_typescript@5.9.3/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.19.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-01-18T03:44:08Z&#34;,&#34;project_hash&#34;:&#34;096945e3&#34;,&#34;cli_path&#34;:&#34;/tmp/tmp-4679-4vC7VH3IVm53/node_modules/prisma/build/index.js&#34;,&#34;cli_path_hash&#34;:&#34;ecdd8a77&#34;,&#34;en node ex.j�� run build k/zenstack-v3/zenstack-v3/node_modules/.bin/node (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Address feedback on client API extensions and query args Fix upsert validation to merge $create and $update schemas Jan 18, 2026
Copilot AI requested a review from ymc9 January 18, 2026 03:55
@ymc9 ymc9 marked this pull request as ready for review January 18, 2026 04:07
@ymc9 ymc9 merged commit eff3502 into feat/client-extension Jan 18, 2026
4 checks passed
@ymc9 ymc9 deleted the copilot/sub-pr-603 branch January 18, 2026 04:07
ymc9 added a commit that referenced this pull request Jan 18, 2026
…sion (#603)

* feat(orm): implement client API extensions, refactor query args extension

* address PR comments

* Fix upsert validation to merge $create and $update schemas (#604)

* Initial plan

* fix: merge $create and $update schemas for upsert validation

- Handle upsert operation specially to match TypeScript type behavior
- When both $create and $update schemas exist, merge them for upsert
- Add test case to verify the fix works correctly

Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>

* fix: improve comment accuracy about Zod merge behavior

Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>

* minor fixes

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants